<html>
<!-- Copyright (C) 2019 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<head>
    <title>Load html over XMLHttpRequest</title>
</head>
<body>
    <!-- Ensure HTML elements exist before executing JavaScript -->
    <h1 id="title">Loaded HTML should appear below on success</h1>
    <hr>
    <div id="assets_html"></div>
    <div id="res_html"></div>

    <!-- Load html file from android_assets -->
    <script type="text/javascript">
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
                document.getElementById("assets_html").innerHTML = this.responseText;
            } else if (this.status !== 200) {
                document.getElementById("assets_html").innerHTML =
                        "Loading file from assets failed (status=" + this.status + ")";
            }
        };
        xhr.onerror = function() {
            document.getElementById("assets_html").innerHTML = "Loading file from assets failed";
        };
        xhr.open("GET", 'https://example.com/androidx_webkit/example/assets/www/some_text.html', true);
        xhr.send();
    </script>

    <!-- Load html file from android_resources -->
    <script type="text/javascript">
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
                document.getElementById("res_html").innerHTML = this.responseText;
            } else if (this.status !== 200) {
                document.getElementById("res_html").innerHTML =
                        "Loading file from resources failed (status=" + this.status + ")";
            }
        };
        xhr.onerror = function() {
            document.getElementById("res_html").innerHTML = "Loading file from resources failed";
        };
        xhr.open("GET", 'https://example.com/androidx_webkit/example/res/raw/some_text.html', true);
        xhr.send();
    </script>
</body>
</html>
